package com.service;

import com.enums.ApiReturnCodeEnum;
import com.util.RestException;
import com.util.UserLocal;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * @author linyukun
 * @date 2022/7/7 10:42
 */
@Service
public class LoginServiceImpl {
    /**
     * 强制登录
     * 2022-10-15 09:10改为userid 不要使用user_name了
     */
    public static String isLogin() {
        //String userName = UserLocal.get().getUserName();
        Long userId = UserLocal.get().getId();
        if (ObjectUtils.isEmpty(userId)) {
            //强制登录
            throw new RestException(ApiReturnCodeEnum.NO_LOGIN);
        }
        return userId.toString();
    }


    public void judgeIsOnTimeRequest(Map<String,String> map,String key){
        synchronized (map){
            if(map.containsKey(key)){
                throw new RestException("已经有人操作了，请刷新页面重新请求");
            }
            map.put(key,key);
        }
    }
}
